<script setup>
import { nextTick, reactive, ref } from "vue";
import SearchTable from "@/components/SearchTable.vue";
import JsonEditorVue from 'json-editor-vue'
import testResultApi from "@/api/testResultApi";

const searchForm = ref();
const searchListTable = ref();
const searchModel = ref({
    schoolId: "",
    studyCode: "",
    name: ""
});

const scroll = ref({
    x: 1500,
    y: 800
})

const columns = [
    {
        title: "上报成绩入参",
        dataIndex: "reqParam",
        width: 240,
        ellipsis: true
    },
    {
        title: "计划名称",
        dataIndex: "planName",
        width: 150
    },
    {
        title: "上报时间",
        dataIndex: "createTime",
        width: 100,
    },
    {
        title: "处理结果",
        slotName: "flag",
        width: 100,
    },
    {
        title: "错误详情",
        dataIndex: "reason",
        width: 100,
    },
    {
        title: "操作",
        slotName: "action",
        fixed: "right",
        width: 150,
    },
];

const currentLog = ref({ reqParam: {} });
const search = () => {
    searchListTable.value.load();
};

const visible = ref(false);
const viewLog = (record) => {
    visible.value = true
    currentLog.value.reqParam = JSON.parse(record.reqParam);
}

const retryLog = (record) => {
    testResultApi.retry(record).then(res => {
        Message.success("操作成功");
    })
}




</script>
<template>
    <div class="main-con">
        <a-card style="margin-bottom: 10px;">
            <a-form ref="searchForm" :model="searchModel" layout="inline">
                <a-form-item field="reqParam" label="日志关键词">
                    <a-input v-model="searchModel.reqParam" placeholder="请输入日志关键词"></a-input>
                </a-form-item>
                <a-form-item field="reqParam" label="处理结果">
                    <a-select v-model="searchModel.flag" allow-clear style="width: 200px;" placeholder="请选择">
                        <a-option value="">全部</a-option>
                        <a-option value="1">成功</a-option>
                        <a-option value="2">错误</a-option>
                    </a-select>
                </a-form-item>
                <a-form-item>
                    <a-space>
                        <a-button type="primary" @click="search">查询</a-button>
                        <a-button @click="searchForm.resetFields()">重置</a-button>
                    </a-space>
                </a-form-item>
            </a-form>
        </a-card>
        <search-table ref="searchListTable" :params="searchModel" :scroll="scroll" url="/admin/v1/log/queryPage"
            :auto-load="true" :columns="columns">

            <template #flag="{ record }">
                <a-tag :color="record.flag == 1 ? '' : 'red'">
                    {{ record.flag == "1" ? "成功" : "错误" }}
                </a-tag>
            </template>
            <template #action="{ record }">
                <a-space>
                    <a-button size="mini" @click="viewLog(record)" type="primary">查看</a-button>
                    <a-button size="mini" v-if="record.flag != 1" @click="retryLog(record)">重试</a-button>
                </a-space>
            </template>
        </search-table>
    </div>

    <a-modal v-model:visible="visible" width="600px" title="成绩上传记录" :footer="null">
        <div style="height: 600px;">
            <JsonEditorVue :height="500" :mainMenuBar="true" :navigationBar="false" :statusBar="false" :readOnly="true"
                v-model="currentLog.reqParam" />
        </div>
    </a-modal>


</template>
<style></style>